package com.ycy.upload;

import java.util.Arrays;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

public class PwdPool{
	private static Logger logger = LogManager.getLogger(PwdPool.class);

	private static Set<String> POOL = new CopyOnWriteArraySet<String>();

	public static boolean add(String pwd){
		return POOL.add(pwd);
	}

	public static void clear(){
		POOL = new CopyOnWriteArraySet<String>();
	}

	public static String[] getAll(){
		String[] res = POOL.toArray(new String[0]);
		Arrays.sort(res);
		return res;
	}

	public static boolean contain(String pwd){
		if (pwd == null) {
			return false;
		}
		boolean tf = false;
		for (String p : POOL) {
			if (p.equals(pwd)) {
				tf = true;
				break;
			}
		}
		return tf;
	}

	public static boolean remove(String pwd){
		return POOL.remove(pwd);
	}
}
